<?php

/*
=====================================================
 Generic Toolbox - by Carl Wells
-----------------------------------------------------
-----------------------------------------------------
 Copyright (c) 2009 Carl Wells
=====================================================
 THIS IS COPYRIGHTED SOFTWARE
 PLEASE READ THE LICENSE AGREEMENT
=====================================================
 File: system/core/category.class.php
-----------------------------------------------------
 Purpose: Model of a Category.
=====================================================
*/

class Category
{	

	var $catArray;

	// CONTRUCTOR
	function Category(){
		$this->catArray = array();
    }
    
    
    // grab the sectors from a db and return an array
    function getCategories($id){
		require_once ( SITEBASE."/system/db/dbCategory.class.php" );
		
	   // require_once("system/db/dbCategory.class.php");
	    $db = new Dbcategory();
	    
	    $parentResult = $db->selectQuery("SELECT DISTINCT `parent` FROM `categories` WHERE `sectorId` = ".$id.";");
	    print(mysql_num_rows($parentResult)."dsfs<br/>");
	    while($parentArray = mysql_fetch_array($parentResult)){
	   	/* print_r($parentArray['parent'] != NULL);
	    	// connect to database
			$result =  $db->selectQuery("SELECT * FROM `categories` WHERE `sectorId` = ".$id." AND `parent` = '".$parentArray['parent']."' ;");
			while( $array = mysql_fetch_array($result) ){
				$this->catArray[] = $array;
			}  */ 
			//print_r($parentArray);
		 }
	   
		// return data as an array;
		return $this->catArray;
    }
    
    // grab a specific sector from a db and return an array
    function getIndividualCategory($id){
	    require_once ( SITEBASE."/system/db/dbCategory.class.php" );
	    $db = new Dbcategory();
   	 	// connect to database
		$result =  $db->selectQuery("SELECT * FROM `categories` WHERE `id` = ".$id.";");
		$array = $db->returnArray($result);
		// return data as an array;
		return $array;
    }
    
}

?>